import type {
  SupportFilterField,
  SupportOrderField,
  View,
  CompatibilityModeView,
  SystemFilter,
  CompatibilityModelSystemFilter,
  CustomComponent as OriginCustomComponent,
  SystemFilterItem,
  OnSmartSearch,
  Ref,
} from '../searchform/interface';
import type { SearchFormProps } from '../searchform';
import type { CompanyViewAuth } from './subcomponents/config/components/SaveAsModal';

export interface SmartSearchSchema {
  supportFilterFields: SupportFilterField[]; // 支持查询字段
  supportOrderFields?: SupportOrderField[]; // 支持排序字段
  systemViews: View[]; // 全字段
  systemFilters?: SystemFilter[]; // 系统筛选器
}

export interface SmartSearchCompatibilityModeSchema {
  supportFilterFields: SupportFilterField[]; // 支持查询字段
  systemViews: CompatibilityModeView[]; // 全字段
  systemFilters?: CompatibilityModelSystemFilter[]; // 系统筛选器
}

export type OnSearch = OnSmartSearch;

export type OnSimpleSearch = (params: any, isInit?: boolean) => void;

export type SmartSearchRef = Ref;

export interface Multiple {
  mode?: string[]; // 通过mode字段来配置是否是多选的组件列表
  multiple?: string[]; // 通过multiple字段来配置是否是多选的组件列表
}

export type CustomComponent = OriginCustomComponent;

export interface SmartSearchProps
  extends Pick<
    SearchFormProps,
    | 'title'
    | 'pageInfo'
    | 'totalCount'
    | 'onSizeChange'
    | 'extra'
    | 'customComponents'
    | 'uiSchema'
    | 'headerProps'
    | 'showBottomLine'
    | 'style'
    | 'loading'
    | 'showFilter'
    | 'showResetBtn'
    | 'showShrinkBtn'
    | 'searchAfterReset'
    | 'showSearchBtn'
    | 'extraAfterShrinkBtn'
    | 'onReset'
    | 'filterLength'
    | 'filterAutoSearch'
  > {
  searchPanelId: string; // 高级查询器唯一标识id
  userId: string; // 用户id
  mode?: 'simple' | 'advanced' | 'advancedOnly'; // 模式
  singleView?: boolean; // 是否开启单视图模式
  schema: SmartSearchSchema | SmartSearchCompatibilityModeSchema; // 字段配置
  hidePrintBtn?: boolean; //是否显示视图打印按钮(在dev环境下)
  placeholder?: string; // 简易查询的placeholder
  onSimpleSearch?: OnSimpleSearch; // 简易查询回调
  onSearch: OnSearch; // 点击查询的回调
  configModalSize?: { width: number; height: number }; // 配置弹框的大小
  ref?: SmartSearchRef;
  isCompatibilityMode?: boolean; // 是否是兼容模式
  showSplitLine?: boolean; // 是否显示分割线
  onViewChange?: (view: View | CompatibilityModeView) => void; // 视图切换的回调
  initView?: View | CompatibilityModeView; // 自定义初始视图
  initParams?: SystemFilterItem[]; // 初始查询参数
  onValueChange?: (value: SystemFilterItem[], filterValue: any) => void; // 输入值改变的回调
  fieldTransfer?: boolean; // 使用穿梭框来配置字段
  hideOrderField?: boolean; // 隐藏排序字段的配置
  multiple?: Multiple; // 自定义组件的多选属性配置
  showDisplayConfig?: boolean; // 是否在配置弹框中显示“显示配置”
  paramsModeOnViewChange?: 'clear' | 'initParams' | 'latest'; // 当前视图切换时，表单值的处理模式 clear: 清除表单值，initParams：回显接收到的initParams，latest：回显上一个视图最新的表单值
  companyViewAuth?: CompanyViewAuth; // 是否有共享视图权限，默认为 write
  isCustomParams?: boolean;
  isAutoSearch?: boolean; // 是否开启自动搜索
  [key: string]: any;
}

export interface SaveViewProps {
  views: View[]; // 视图列表
  type: 'save' | 'saveAs' | 'setDefault' | 'rename' | 'delete';
  hideModal: () => void; // 隐藏弹窗的回调
  clearFilterView?: View; // 需要清除筛选器
  operateView?: View; // 当前操作的视图
  defaultView?: DefaultView; // 默认视图
  viewType: View['viewType'];
}
